Source of Two Seperate scripts, each in its own section, is shown below. This Perl code demonstrates an easy way to discover if a visiting user agent can execute javascript. This is helpful if you want to generate different output for visitors that can't execute javascript (such as search engine spiders, text-only browsers, various web browsers for the disabled). See an example of this code in action at AS A SIDE NOTE, I wanted to mention that the ooOPps! code library at http://ooopps.sourceforge.net/pub has had a lot of updates and new additions in the last couple weeks. You might want to stop by. Send me (via email) your open source code contributions, programming examples, and Perl jOOkes for inclusion/acknowledgement in the ooOPps! code library. ooOPps! is the Ongoing Object-Oriented Perl Project. -----=// SCRIPT #1 of 2 //=--------------------------------------------------- Filename: canjs.pl Pupose: Provides the ability for a CGI script to detect an HTTP User-Agent's JavaScript support. #!/usr/bin/perl -w use strict; BEGIN { print(<<'__HDR__'); } Content-Length: 88 Content-Type: application/x-javascript Last-Modified: Wed, 08 May 2002 23:09:05 GMT // serves as user agent javascript support determinant var canjs = true; // whatever... __HDR__ BEGIN { push(@INC,'./modules') } use Futils; # Futils transparently handles file locking on many platforms. =NOTES Get a copy of Futils.pm and put it into a sub-directory of your cgi-bin named 'modules'. Futils.pm is freely available at the URL below. URL: http://ooopps.sourceforge.net/cgi-bin/archive.pl/pub/modules/Futils.pm Create another subdirectory inside your cgi-bin and name it 'jscache'. Set permissions on the 'jscache' directory so that it is writable by Perl. Usually this means you need to set the directory permissions to 0755, or with some server configurations a setting of 0777 is needed. =cut my($f) = Futils->new('--fatals-as-warning'); my($id) = join ( '', map { sprintf('_0%lo', ord($_)) } split(//,substr($ENV{'QUERY_STRING'}||'',0,16)) ); if (length($id)) { $f->write_file ( 'filename' => qq[./jscache/$id], 'content' => '', '--empty-writes-OK' ); } exit; =pod AUTHOR Tommy Butler phone: (817)-468-7716 6711 Forest Park Dr Arlington, TX 76001-8403 COPYRIGHT Copyright Tommy Butler. All rights reserved BUGS TO Tommy Butler LISCENCE This software is free to use, modify, and distribute under the terms of the GNU General Public License. See http://www.gnu.org/copyleft/gpl.html =cut -----=// SCRIPT #2 of 2 //=--------------------------------------------------- Filename: canseejs.pl Pupose: Demonstrates how to do the actual detection of an HTTP User-Agent's ability to execute JavaScript code. #!/usr/bin/perl -w use strict; use vars qw( $TIMEOUT $canjsID ); $TIMEOUT = 6; BEGIN { $|=1; $canjsID = join('',gmtime,$$); my($o) = <<'__HTHDR__'; $o =~ s/canjsID/$canjsID/; print($o); } Cache-Control: no-cache Content-Type: text/html; charset=iso-8859-1 User Agent JavaScript Support Test

 

__HTHDR__ $canjsID = join ( '', map { sprintf('_0%lo', ord($_)) } split(//,substr($canjsID,0,16)) ); while ($TIMEOUT) { if (-e qq[./jscache/$canjsID]) { print(<<'__CANJS__');

Your browser appears to support JavaScript, and is configured to enable the execution of JavaScript code.

__CANJS__ unlink(qq[./jscache/$canjsID]) or warn (qq[Can't unlink ./jscache/$canjsID $!]); print(<<'__HTFTR__') and exit;

 

__HTFTR__ } else { --$TIMEOUT; my($pid) = fork; $|=1; die(qq[Can't fork $!]) unless defined($pid); if ($pid) { waitpid($pid,0); print(qq[\012]); } else { eval('sleep(1)') and exit; } } } print(<<'__NOJS__');

Your browser does not appear to support JavaScript, or is configured such that the execution of JavaScript code is disabled.

__NOJS__ print(<<'__HTFTR__') and exit;

 

__HTFTR__ -- -Tommy Butler see if I'm online »http://ooopps.sourceforge.net/online Tommy Butler phone: (817)-468-7716 6711 Forest Park Dr Arlington, TX 76001-8403 Download my résumé in PDF, MS Word, HTML, text http://www.atrixnet.com/ the ooOPps Code Library http://ooopps.sourceforge.net/pub/